var express = require('express');
var ejs = require('ejs');
global.config = require('config').values;
var app = express();
app.engine('.js', ejs.__express);
app.set('view engine', 'js');
app.use('/', express.static(__dirname+'/'));

/*
    客服端初始接口
    获取路由，获取客服端代码
*/
app.get('/init.js', function(req, res){
    var data = {
        host:config.web.host,
        imHost:config.im.host
    };
    res.setHeader('Content-Type', 'application/x-javascript');
    res.render(__dirname+'/js/init.js', data);
});

/*
    client逻辑代码下发
*/
app.get('/client.js', function(req, res){
    res.setHeader('Content-Type', 'application/x-javascript');
    res.render(__dirname+'/js/client.js');
});

/*
    需要的文件下发
*/
app.get('/socket.js', function(req, res){
    var data = {
        host:config.web.host
    };
    res.setHeader('Content-Type', 'application/x-javascript');
    res.render(__dirname+'/js/socket.io.js', data);
});


app.listen(config.web.port);
console.log('web listening on port '+config.web.port);